const app = getApp()
import * as THREE from './three.weapp.js'
import TWEEN from './tween.js';

var ZW_bFirst = true;
var ZW_ProcessValue = 0;

var LAMER_GLOBAL_URL = 'http://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamerwx';
var Current_Room_Index = 0;

var that;
var canvas;
var STATE = {
  NONE: -1,
  TOUCH_ROTATE: 0,
  TOUCH_ZOOM_PAN: 1,
  TOUCH_PAN: 2
};

var ZW_PixelRatio = 2;
var ZW_ROOM1_STATE = 0;
var ZW_ROOM2_STATE = 0;
var ZW_ROOM3_STATE = 0;
var ZW_ROOM4_STATE = 0;
var ZW_ROOM5_STATE = 0;
var ZW_ROOM6_STATE = 0;

var _state = STATE.NONE;
var _movePrev = new THREE.Vector2();
var _moveCurr = new THREE.Vector2();
var _touchZoomDistanceStart = 1;
var _touchZoomDistanceEnd = 1;
var _zoomStart = new THREE.Vector2();
var _panStart = new THREE.Vector2();
var _panEnd = new THREE.Vector2();

var ZW_Scene;
var ZW_raycaster;
var ZW_normalCamera;
var ZW_CurrentModel = '';

var imageWidth = 600;
var imageHieght = 900;
var ZW_bFlying = false;

var _clickStart = new THREE.Vector2();
var _clickEnd = new THREE.Vector2();

var LoadNum = 0;

var Back_Img_Type = 1;  //大厅背景类型，1为早上，2为中午，3为晚上

var ZW_RoomStateArray = [true, true, true, true, true]; //房间状态的数组，默认是全部开启的

//设置房间是否锁定，index为索引1-5，state为是否可用，false是锁定，true是放开
function SetRoomState(index, state) {
  ZW_RoomStateArray[index - 1] = state;

  if (index == 1 && ZW_Scene.getObjectByName('backimg1')) {
    if (state) {
      ZW_Scene.getObjectByName('backimg1').getObjectByName('tip13').getObjectByName('lock').visible = false;
    } else {
      ZW_Scene.getObjectByName('backimg1').getObjectByName('tip13').getObjectByName('lock').visible = true;
    }
  } else if (index == 2 && ZW_Scene.getObjectByName('backimg1')) {
    if (state) {
      ZW_Scene.getObjectByName('backimg1').getObjectByName('tip23').getObjectByName('lock').visible = false;
    } else {
      ZW_Scene.getObjectByName('backimg1').getObjectByName('tip23').getObjectByName('lock').visible = true;
    }
  } else if (index == 3 && ZW_Scene.getObjectByName('backimg2')) {
    if (state) {
      ZW_Scene.getObjectByName('backimg2').getObjectByName('tip33').getObjectByName('lock').visible = false;
    } else {
      ZW_Scene.getObjectByName('backimg2').getObjectByName('tip33').getObjectByName('lock').visible = true;
    }
  } else if (index == 4 && ZW_Scene.getObjectByName('backimg3')) {
    if (state) {
      ZW_Scene.getObjectByName('backimg3').getObjectByName('tip43').getObjectByName('lock').visible = false;
    } else {
      ZW_Scene.getObjectByName('backimg3').getObjectByName('tip43').getObjectByName('lock').visible = true;
    }
  } else if (index == 5 && ZW_Scene.getObjectByName('backimg3')) {
    if (state) {
      ZW_Scene.getObjectByName('backimg3').getObjectByName('tip53').getObjectByName('lock').visible = false;
    } else {
      ZW_Scene.getObjectByName('backimg3').getObjectByName('tip53').getObjectByName('lock').visible = true;
    }
  }

}

function initParams() {
  ZW_bFirst = true;
  ZW_ProcessValue = 0;

  LAMER_GLOBAL_URL = 'http://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamerwx';
  Current_Room_Index = 0;

  that = null;
  canvas = null;
  STATE = {
    NONE: -1,
    TOUCH_ROTATE: 0,
    TOUCH_ZOOM_PAN: 1,
    TOUCH_PAN: 2
  };

  ZW_ROOM1_STATE = 0;
  ZW_ROOM2_STATE = 0;
  ZW_ROOM3_STATE = 0;
  ZW_ROOM4_STATE = 0;
  ZW_ROOM5_STATE = 0;
  ZW_ROOM6_STATE = 0;

  _state = STATE.NONE;
  _movePrev = new THREE.Vector2();
  _moveCurr = new THREE.Vector2();
  _touchZoomDistanceStart = 1;
  _touchZoomDistanceEnd = 1;
  _zoomStart = new THREE.Vector2();
  _panStart = new THREE.Vector2();
  _panEnd = new THREE.Vector2();

  

  ZW_Scene = null;

  ZW_CurrentModel = '';
}

function getMouseOnScreen(pageX, pageY) {
  var vector = new THREE.Vector2();

  vector.set(
    1.0 * (pageX) / ZW_Width1,
    1.0 * (pageY) / ZW_Height1
  );

  return vector;
}

function getMouseOnCircle(pageX, pageY) {
  var vector = new THREE.Vector2();
  vector.set(
    ((pageX - canvas.width * 0.5) / (canvas.width * 0.5)),
    ((canvas.height + 2 * (0 - pageY)) / canvas.width)
  );

  return vector;
}

function RotateCamera() {
  if (_state === STATE.TOUCH_ROTATE) {
    var moveDirection = new THREE.Vector3();
    var angle;

    moveDirection.set(_moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0);
    angle = moveDirection.length();

    if (angle && Math.abs(angle < 0.2)) { //解决双指缩放时导致的角度突变

      var xOffset = _moveCurr.x - _movePrev.x;
      var yOffset = _moveCurr.y - _movePrev.y;
      xOffset /= 4;
      yOffset /= 4;
      yOffset = 0;
      ZW_Scene.getObjectByName('backimg1').position.x += xOffset;
      ZW_Scene.getObjectByName('backimg2').position.x += xOffset;
      ZW_Scene.getObjectByName('backimg3').position.x += xOffset;
      var pos1 = -(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0);
      var pos2 = 0;
      var pos3 = (0.5 * 2671 / 750 + 0.5 * 2100 / 750.0);
      if (ZW_Scene.getObjectByName('backimg1').position.x > -0.01 && ZW_Scene.getObjectByName('backimg1').position.x < 0.01) {
        ZW_Scene.getObjectByName('backimg2').position.x = ZW_Scene.getObjectByName('backimg1').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (+(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));
        ZW_Scene.getObjectByName('backimg3').position.x = ZW_Scene.getObjectByName('backimg1').position.x - (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * 1.0 * 2671 / 750;
      }

      if (ZW_Scene.getObjectByName('backimg2').position.x > -0.01 && ZW_Scene.getObjectByName('backimg2').position.x < 0.01) {
        ZW_Scene.getObjectByName('backimg1').position.x = ZW_Scene.getObjectByName('backimg2').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (-(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));
        ZW_Scene.getObjectByName('backimg3').position.x = ZW_Scene.getObjectByName('backimg2').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (+(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));
      }

      if (ZW_Scene.getObjectByName('backimg3').position.x > -0.01 && ZW_Scene.getObjectByName('backimg3').position.x < 0.01) {
        ZW_Scene.getObjectByName('backimg1').position.x = ZW_Scene.getObjectByName('backimg3').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * 1.0 * 2671 / 750;
        ZW_Scene.getObjectByName('backimg2').position.x = ZW_Scene.getObjectByName('backimg3').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (-(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));
      }

      ZW_Scene.getObjectByName('backimg1').position.y += yOffset;
      ZW_Scene.getObjectByName('backimg2').position.y += yOffset;
      ZW_Scene.getObjectByName('backimg3').position.y += yOffset;

      if (ZW_Scene.getObjectByName('backimg1').position.y > 0.05 || ZW_Scene.getObjectByName('backimg1').position.y < -0.05) {
        ZW_Scene.getObjectByName('backimg1').position.y -= yOffset;
        ZW_Scene.getObjectByName('backimg2').position.y -= yOffset;
        ZW_Scene.getObjectByName('backimg3').position.y -= yOffset;
      }

      console.log(ZW_Scene.getObjectByName('backimg2').position.y);
      UpdateTipState();

    }
    _movePrev.copy(_moveCurr);
  }
};

function ControlUpdate() {
  RotateCamera();
}


function GetImagePos(x, y) {
  var tip1Width = 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
  var tip1Height = 0.1 * (imageHieght / imageWidth) * ((canvas.width / canvas.height) / 0.5633802816901409);

  return [tip1Width * (imageWidth / 2 - x) / imageWidth, tip1Height * (y - imageHieght / 2) / imageHieght];
  var backImg = ZW_Scene.getObjectByName(name);
  backImg.position.x = tip1Width * (imageWidth / 2 - x) / imageWidth;
  backImg.position.y = tip1Height * (y - imageHieght / 2) / imageHieght;
  backImg.position.z = z;
}

function OnModelLoaded(){
    console.log('finish!');

    // wx.showToast({
    //   title: '加载完成',
    //   icon: 'success',
    //   duration: 2000
    // })

        SetRoomState(1, true);
        SetRoomState(2, true);
        SetRoomState(3, true);
        SetRoomState(4, true);
        SetRoomState(5, false);

        SetRoom(app.globalData.indexTurnDoor != -1 ? app.globalData.indexTurnDoor : 1);

       // that.onLoadingFinish();
}

function AddImage(name, url, width, height, x) {
    // console.log(canvas.width);
    // console.log(canvas.height);
    var baseWidth = 0.14 * canvas.width / 360.0;
    // var tip1Width = (320.0/(canvas.width/ZW_PixelRatio))*0.1;
    // var tip1Height = (320.0/(canvas.width/ZW_PixelRatio))*0.1*(height/width);

    var titleUrl1 = '';
    var titleUrl2 = '';
    var titleUrl3 = '';
    var titleUrl4 = '';
    var titleUrl5 = '';
    if (Back_Img_Type == 1) {
        titleUrl1 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door1-title_morning.png";
        titleUrl2 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door2-title_morning.png";
        titleUrl3 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door3-title_morning.png";
        titleUrl4 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door4-title_morning.png";
        titleUrl5 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0430/index-door5-title_morning.png";
    } else if (Back_Img_Type == 2) {
        titleUrl1 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door1-title_day.png";
        titleUrl2 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door2-title_day.png";
        titleUrl3 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door3-title_day.png";
        titleUrl4 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door4-title_day.png";
        titleUrl5 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0430/index-door5-title_day.png";
    } else if (Back_Img_Type == 3) {
        titleUrl1 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door1-title_night.png";
        titleUrl2 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door2-title_night.png";
        titleUrl3 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door3-title_night.png";
        titleUrl4 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0504/index-door4-title_night.png";
        titleUrl5 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0430/index-door5-title_night.png";
    }

    var tip1Width = width * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
    var tip1Height = height * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);

    var tip1X = x * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);

    var plane1;

    const texture1 = new THREE.TextureLoader().load(url, function (texture) {
        LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
    });

    texture1.minFilter = THREE.LinearFilter;
    texture1.magFilter = THREE.LinearFilter;
        var geometry1 = new THREE.PlaneGeometry(tip1Width, tip1Height);

        var material1 = new THREE.MeshBasicMaterial({
            color: 0xffffff,
            map: texture1,
            // alphaMap:texture,
            transparent: true,
            //wireframe:true
        });

        plane1 = new THREE.Mesh(geometry1, material1);
        plane1.name = name;
        plane1.position.x = tip1X;
        plane1.position.y = -0.02;
        plane1.position.z = 1.88;
        ZW_Scene.add(plane1);

        var planeAlpha = 0.0;

        if (name == 'backimg1') {
            var geometry2 = new THREE.PlaneGeometry(0.6 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 0.98 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material2 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: planeAlpha
                //wireframe:true
            });
            var plane2 = new THREE.Mesh(geometry2, material2);
            plane2.name = 'door1';
            plane2.position.x = -0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane2.position.y = 0.30 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane2);

            var geometry3 = new THREE.PlaneGeometry(0.6 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 0.98 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material3 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: planeAlpha
                //wireframe:true
            });
            var plane3 = new THREE.Mesh(geometry3, material3);
            plane3.name = 'door2';
            plane3.position.x = 1.22 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane3.position.y = 0.30 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane3);

            const texture11 = new THREE.TextureLoader().load(titleUrl1, function (texture) {
                LoadNum--;
                if(LoadNum == 0) OnModelLoaded();
            });
            texture11.minFilter = THREE.LinearFilter;
            texture11.magFilter = THREE.LinearFilter;

            var geometry11 = new THREE.PlaneGeometry(1.25 * (465 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (124 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material11 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture11
                //wireframe:true
            });
            var plane11 = new THREE.Mesh(geometry11, material11);
            plane11.name = 'tip11';
            plane11.position.x = -0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane11.position.y = 1.0 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane11);

            const texture12 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0430/1.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture12.minFilter = THREE.LinearFilter;
            texture12.magFilter = THREE.LinearFilter;

            var geometry12 = new THREE.PlaneGeometry(1.25 * (390 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (86 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material12 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture12
                //wireframe:true
            });
            var plane12 = new THREE.Mesh(geometry12, material12);
            plane12.name = 'tip12';
            plane12.position.x = -0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane12.position.y = -0.26 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane12);

            const texture13 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/btn-door-enter.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture13.minFilter = THREE.LinearFilter;
            texture13.magFilter = THREE.LinearFilter;

            var geometry13 = new THREE.PlaneGeometry(1.25 * (300 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (60 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material13 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture13
                //wireframe:true
            });
            var plane13 = new THREE.Mesh(geometry13, material13);
            plane13.name = 'tip13';
            plane13.position.x = -0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane13.position.y = -0.45 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane13);

            const texture0 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/lock.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture0.minFilter = THREE.LinearFilter;
            texture0.magFilter = THREE.LinearFilter;

            var geometry0 = new THREE.PlaneGeometry(1.25 * (16 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (18 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material0 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture0
                //wireframe:true
            });
            var plane0 = new THREE.Mesh(geometry0, material0);
            plane0.name = 'lock';
            plane0.visible = false;
            plane0.position.x = -0.011 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane13.add(plane0);

            const texture14 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0429/index-door-zhinan.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture14.minFilter = THREE.LinearFilter;
            texture14.magFilter = THREE.LinearFilter;

            var geometry14 = new THREE.PlaneGeometry(1.25 * (110 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (23 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material14 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture14
                //wireframe:true
            });
            var plane14 = new THREE.Mesh(geometry14, material14);
            plane14.name = 'tip14';
            plane14.position.x = -0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane14.position.y = -0.58 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane14.scale.x = 2;
            plane14.scale.y = 2;
            plane14.scale.y = 2;
            plane1.add(plane14);

            const texture21 = new THREE.TextureLoader().load(titleUrl2, function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture21.minFilter = THREE.LinearFilter;
            texture21.magFilter = THREE.LinearFilter;

            var geometry21 = new THREE.PlaneGeometry(1.25 * (418 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (123 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material21 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture21
                //wireframe:true
            });
            var plane21 = new THREE.Mesh(geometry21, material21);
            plane21.name = 'tip21';
            plane21.position.x = 1.22 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane21.position.y = 1.0 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane21);

            const texture22 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0430/2.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture22.minFilter = THREE.LinearFilter;
            texture22.magFilter = THREE.LinearFilter;

            var geometry22 = new THREE.PlaneGeometry(1.25 * (359 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (86 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material22 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture22
                //wireframe:true
            });
            var plane22 = new THREE.Mesh(geometry22, material22);
            plane22.name = 'tip22';
            plane22.position.x = 1.22 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane22.position.y = -0.26 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane22);

            const texture23 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/btn-door-enter.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture23.minFilter = THREE.LinearFilter;
            texture23.magFilter = THREE.LinearFilter;

            var geometry23 = new THREE.PlaneGeometry(1.25 * (300 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (60 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material23 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture23
                //wireframe:true
            });
            var plane23 = new THREE.Mesh(geometry23, material23);
            plane23.name = 'tip23';
            plane23.position.x = 1.22 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane23.position.y = -0.45 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane23);

            const texture00 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/lock.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture00.minFilter = THREE.LinearFilter;
            texture00.magFilter = THREE.LinearFilter;

            var geometry00 = new THREE.PlaneGeometry(1.25 * (16 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (18 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material00 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture00
                //wireframe:true
            });
            var plane00 = new THREE.Mesh(geometry00, material00);
            plane00.name = 'lock';
            plane00.visible = false;
            plane00.position.x = -0.011 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane23.add(plane00);

            const texture24 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0429/index-door-zhinan.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture24.minFilter = THREE.LinearFilter;
            texture24.magFilter = THREE.LinearFilter;

            var geometry24 = new THREE.PlaneGeometry(1.25 * (110 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (23 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material24 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture24
                //wireframe:true
            });
            var plane24 = new THREE.Mesh(geometry24, material24);
            plane24.name = 'tip24';
            plane24.scale.x = 2;
            plane24.scale.y = 2;
            plane24.scale.y = 2;
            plane24.position.x = 1.22 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane24.position.y = -0.58 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane24);
        }

        if (name == 'backimg2') {
            var geometry2 = new THREE.PlaneGeometry(0.6 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 0.98 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material2 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: planeAlpha
                //wireframe:true
            });
            var plane2 = new THREE.Mesh(geometry2, material2);
            plane2.name = 'door3';
            plane2.position.y = 0.30 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane2);

            const texture31 = new THREE.TextureLoader().load(titleUrl3, function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture31.minFilter = THREE.LinearFilter;
            texture31.magFilter = THREE.LinearFilter;

            var geometry31 = new THREE.PlaneGeometry(1.25 * (433 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (123 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material31 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture31
                //wireframe:true
            });
            var plane31 = new THREE.Mesh(geometry31, material31);
            plane31.name = 'tip31';
            plane31.position.y = 1.0 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane31);

            const texture32 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0430/3.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture32.minFilter = THREE.LinearFilter;
            texture32.magFilter = THREE.LinearFilter;

            var geometry32 = new THREE.PlaneGeometry(1.25 * (353 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (86 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material32 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture32
                //wireframe:true
            });
            var plane32 = new THREE.Mesh(geometry32, material32);
            plane32.name = 'tip32';
            plane32.position.y = -0.26 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane32);

            const texture33 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/btn-door-enter.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture33.minFilter = THREE.LinearFilter;
            texture33.magFilter = THREE.LinearFilter;

            var geometry33 = new THREE.PlaneGeometry(1.25 * (300 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (60 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material33 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture33
                //wireframe:true
            });
            var plane33 = new THREE.Mesh(geometry33, material33);
            plane33.name = 'tip33';
            plane33.position.y = -0.45 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane33);

            const texture0 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/lock.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture0.minFilter = THREE.LinearFilter;
            texture0.magFilter = THREE.LinearFilter;

            var geometry0 = new THREE.PlaneGeometry(1.25 * (16 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (18 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material0 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture0
                //wireframe:true
            });
            var plane0 = new THREE.Mesh(geometry0, material0);
            plane0.name = 'lock';
            plane0.visible = false;
            plane0.position.x = -0.011 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane33.add(plane0);

            const texture34 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0429/index-door-zhinan.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture34.minFilter = THREE.LinearFilter;
            texture34.magFilter = THREE.LinearFilter;

            var geometry34 = new THREE.PlaneGeometry(1.25 * (110 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (23 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material34 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture34
                //wireframe:true
            });
            var plane34 = new THREE.Mesh(geometry34, material34);
            plane34.name = 'tip34';
            plane34.scale.x = 2;
            plane34.scale.y = 2;
            plane34.scale.y = 2;
            plane34.position.y = -0.58 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane34);
        }


        if (name == 'backimg3') {
            var geometry2 = new THREE.PlaneGeometry(0.6 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 0.98 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material2 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: planeAlpha
                //wireframe:true
            });
            var plane2 = new THREE.Mesh(geometry2, material2);
            plane2.name = 'door4';
            plane2.position.x = -1.2 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane2.position.y = 0.30 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane2);

            var geometry3 = new THREE.PlaneGeometry(0.6 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 0.98 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material3 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: planeAlpha
                //wireframe:true
            });
            var plane3 = new THREE.Mesh(geometry3, material3);
            plane3.name = 'door5';
            plane3.position.x = 0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane3.position.y = 0.30 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane3);

            const texture41 = new THREE.TextureLoader().load(titleUrl4, function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture41.minFilter = THREE.LinearFilter;
            texture41.magFilter = THREE.LinearFilter;

            var geometry41 = new THREE.PlaneGeometry(1.25 * (537 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (124 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material41 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture41
                //wireframe:true
            });
            var plane41 = new THREE.Mesh(geometry41, material41);
            plane41.name = 'tip41';
            plane41.position.x = -1.20 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane41.position.y = 1.0 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane41);

            const texture42 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0430/4.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture42.minFilter = THREE.LinearFilter;
            texture42.magFilter = THREE.LinearFilter;

            var geometry42 = new THREE.PlaneGeometry(1.25 * (390 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (86 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material42 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture42
                //wireframe:true
            });
            var plane42 = new THREE.Mesh(geometry42, material42);
            plane42.name = 'tip42';
            plane42.position.x = -1.20 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane42.position.y = -0.26 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane42);

            const texture43 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/btn-door-enter.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture43.minFilter = THREE.LinearFilter;
            texture43.magFilter = THREE.LinearFilter;

            var geometry43 = new THREE.PlaneGeometry(1.25 * (300 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (60 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material43 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture43
                //wireframe:true
            });
            var plane43 = new THREE.Mesh(geometry43, material43);
            plane43.name = 'tip43';
            plane43.position.x = -1.20 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane43.position.y = -0.45 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane43);

            const texture0 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/lock.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture0.minFilter = THREE.LinearFilter;
            texture0.magFilter = THREE.LinearFilter;

            var geometry0 = new THREE.PlaneGeometry(1.25 * (16 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (18 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material0 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture0
                //wireframe:true
            });
            var plane0 = new THREE.Mesh(geometry0, material0);
            plane0.name = 'lock';
            plane0.visible = false;
            plane0.position.x = -0.011 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane43.add(plane0);

            const texture44 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0429/index-door-zhinan.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture44.minFilter = THREE.LinearFilter;
            texture44.magFilter = THREE.LinearFilter;

            var geometry44 = new THREE.PlaneGeometry(1.25 * (110 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (23 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material44 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture44
                //wireframe:true
            });
            var plane44 = new THREE.Mesh(geometry44, material44);
            plane44.name = 'tip44';
            plane44.scale.x = 2;
            plane44.scale.y = 2;
            plane44.scale.y = 2;
            plane44.position.x = -1.20 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane44.position.y = -0.58 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane44);

            const texture51 = new THREE.TextureLoader().load(titleUrl5, function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture51.minFilter = THREE.LinearFilter;
            texture51.magFilter = THREE.LinearFilter;

            var geometry51 = new THREE.PlaneGeometry(1.25 * (604 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (123 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material51 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture51
                //wireframe:true
            });
            var plane51 = new THREE.Mesh(geometry51, material51);
            plane51.name = 'tip51';
            plane51.position.x = 0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane51.position.y = 1.0 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane51);

            const texture52 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0430/5.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture52.minFilter = THREE.LinearFilter;
            texture52.magFilter = THREE.LinearFilter;

            var geometry52 = new THREE.PlaneGeometry(1.25 * (384 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (86 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material52 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture52
                //wireframe:true
            });
            var plane52 = new THREE.Mesh(geometry52, material52);
            plane52.name = 'tip52';
            plane52.position.x = 0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane52.position.y = -0.26 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane52);

            const texture53 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/btn-door-enter.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture53.minFilter = THREE.LinearFilter;
            texture53.magFilter = THREE.LinearFilter;

            var geometry53 = new THREE.PlaneGeometry(1.25 * (300 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (60 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material53 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture53
                //wireframe:true
            });
            var plane53 = new THREE.Mesh(geometry53, material53);
            plane53.name = 'tip53';
            plane53.position.x = 0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane53.position.y = -0.45 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane53);

            const texture00 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/index/lock.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture00.minFilter = THREE.LinearFilter;
            texture00.magFilter = THREE.LinearFilter;

            var geometry00 = new THREE.PlaneGeometry(1.25 * (16 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (18 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material00 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture00
                //wireframe:true
            });
            var plane00 = new THREE.Mesh(geometry00, material00);
            plane00.name = 'lock';
            plane00.visible = false;
            plane00.position.x = -0.011 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane53.add(plane00);

            const texture54 = new THREE.TextureLoader().load('https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0429/index-door-zhinan.png', function (texture) {
                LoadNum--;
        if(LoadNum == 0) OnModelLoaded();
            });
            texture54.minFilter = THREE.LinearFilter;
            texture54.magFilter = THREE.LinearFilter;

            var geometry54 = new THREE.PlaneGeometry(1.25 * (110 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409), 1.25 * (23 / 750.0) * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409));
            var material54 = new THREE.MeshBasicMaterial({
                color: 0xffffff,
                transparent: true,
                opacity: 1.0,
                map: texture54
                //wireframe:true
            });
            var plane54 = new THREE.Mesh(geometry54, material54);
            plane54.name = 'tip54';
            plane54.scale.x = 2;
            plane54.scale.y = 2;
            plane54.scale.y = 2;
            plane54.position.x = 0.68 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane54.position.y = -0.58 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
            plane1.add(plane54);
        }


}
//随着坐标的变化，更新文字的显示状态
function UpdateTipState() {
  return;
  if (ZW_Scene.getObjectByName('backimg1').position.y < 0.012 && ZW_Scene.getObjectByName('backimg1').position.y > -0.035) {
    var bRoom1 = ZW_Scene.getObjectByName('backimg1').position.x > 0.68 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) - 0.03 &&
      ZW_Scene.getObjectByName('backimg1').position.x < 0.68 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) + 0.03;
    var bRoom2 = ZW_Scene.getObjectByName('backimg1').position.x > -1.22 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) - 0.03 &&
      ZW_Scene.getObjectByName('backimg1').position.x < -1.22 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) + 0.03;
    var bRoom3 = ZW_Scene.getObjectByName('backimg2').position.x > -0.03 && ZW_Scene.getObjectByName('backimg2').position.x < 0.03;
    var bRoom4 = ZW_Scene.getObjectByName('backimg3').position.x > 1.23 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) - 0.03 &&
      ZW_Scene.getObjectByName('backimg3').position.x < 1.23 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) + 0.03;
    var bRoom5 = ZW_Scene.getObjectByName('backimg3').position.x > -0.68 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) - 0.03 &&
      ZW_Scene.getObjectByName('backimg3').position.x < -0.68 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) + 0.03;

    if (bRoom1 || bRoom2 || bRoom3 || bRoom4 || bRoom5) {
      SetRoomTipVisible(true);
    } else {
      SetRoomTipVisible(false);
    }
  } else {
    SetRoomTipVisible(false);
  }
}

//设置房间上文案是否显示
function SetRoomTipVisible(visible) {
  ZW_Scene.getObjectByName('backimg1').getObjectByName('tip11').visible = visible;
  ZW_Scene.getObjectByName('backimg1').getObjectByName('tip12').visible = visible;
  ZW_Scene.getObjectByName('backimg1').getObjectByName('tip13').visible = visible;
  ZW_Scene.getObjectByName('backimg1').getObjectByName('tip14').visible = visible;

  ZW_Scene.getObjectByName('backimg1').getObjectByName('tip21').visible = visible;
  ZW_Scene.getObjectByName('backimg1').getObjectByName('tip22').visible = visible;
  ZW_Scene.getObjectByName('backimg1').getObjectByName('tip23').visible = visible;
  ZW_Scene.getObjectByName('backimg1').getObjectByName('tip24').visible = visible;

  ZW_Scene.getObjectByName('backimg2').getObjectByName('tip31').visible = visible;
  ZW_Scene.getObjectByName('backimg2').getObjectByName('tip32').visible = visible;
  ZW_Scene.getObjectByName('backimg2').getObjectByName('tip33').visible = visible;
  ZW_Scene.getObjectByName('backimg2').getObjectByName('tip34').visible = visible;

  ZW_Scene.getObjectByName('backimg3').getObjectByName('tip41').visible = visible;
  ZW_Scene.getObjectByName('backimg3').getObjectByName('tip42').visible = visible;
  ZW_Scene.getObjectByName('backimg3').getObjectByName('tip43').visible = visible;
  ZW_Scene.getObjectByName('backimg3').getObjectByName('tip44').visible = visible;

  ZW_Scene.getObjectByName('backimg3').getObjectByName('tip51').visible = visible;
  ZW_Scene.getObjectByName('backimg3').getObjectByName('tip52').visible = visible;
  ZW_Scene.getObjectByName('backimg3').getObjectByName('tip53').visible = visible;
  ZW_Scene.getObjectByName('backimg3').getObjectByName('tip54').visible = visible;
}

//开始圆圈动画
function StartCircleAnimation1(name) {

  var circleNode = ZW_Scene.getObjectByName('circle');

  var coords = {
    x: 1
  };
  new TWEEN.Tween(coords)
    .to({
      x: 135
    }, 135.0 / 15.0 * 1000)
    .repeat(1)
    .easing(TWEEN.Easing.Quadratic.Out)
    .onUpdate(function () {

      var num = Math.round(coords.x);

      //console.log(num);
      var offetX0;
      var offetY0;
      offetX0 = picInfo['frames']['circle (' + num + ').png']['frame'].x / (6839.0);
      offetY0 = 1.0 - picInfo['frames']['circle (' + num + ').png']['frame'].y / (6839.0) - 1.0 / 12.0;

      // offetX0 = 0.0/12.0;

      // offetY0 = (1.0-1.0/12.0)-1.0/12.0;
      // console.log(offetX0); 
      //console.log(offetY0);
      var uvArray = circleNode.geometry.faceVertexUvs[0];
      uvArray[0][0].x = offetX0;
      uvArray[0][0].y = offetY0 + 1.0 / 12.0;
      uvArray[0][1].x = offetX0;
      uvArray[0][1].y = offetY0;
      uvArray[0][2].x = offetX0 + 1.0 / 12.0;
      uvArray[0][2].y = offetY0 + 1.0 / 12.0;

      uvArray[1][0].x = offetX0;
      uvArray[1][0].y = offetY0;
      uvArray[1][1].x = offetX0 + 1.0 / 12.0;
      uvArray[1][1].y = offetY0;
      uvArray[1][2].x = offetX0 + 1.0 / 12.0;
      uvArray[1][2].y = offetY0 + 1.0 / 12.0;

      circleNode.geometry.uvsNeedUpdate = true;

    })
    .delay(0)
    .start();
}


function SetRoom(index) {
  if (ZW_bFlying ) return;
  if (!ZW_Scene.getObjectByName("backimg1") || !ZW_Scene.getObjectByName("backimg2") || !ZW_Scene.getObjectByName("backimg3")) return;
  var offsetX = 0;
  var pos1 = ZW_Scene.getObjectByName("backimg1").position.x;
  var pos2 = ZW_Scene.getObjectByName("backimg2").position.x;
  var pos3 = ZW_Scene.getObjectByName("backimg3").position.x;
  if (index == 1) {
    offsetX = 0.68 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) - ZW_Scene.getObjectByName("backimg1").position.x;
  } else if (index == 2) {
    offsetX = -1.22 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) - ZW_Scene.getObjectByName("backimg1").position.x;
  } else if (index == 3) {
    offsetX = 0 - ZW_Scene.getObjectByName("backimg2").position.x;
  } else if (index == 4) {
    offsetX = 1.23 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) - ZW_Scene.getObjectByName("backimg3").position.x;
  } else if (index == 5) {
    offsetX = -0.68 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409) - ZW_Scene.getObjectByName("backimg3").position.x;
  }
  // console.log(0.68 * 0.1 * (canvas.width / canvas.height / 0.5633802816901409));
  // console.log(ZW_Scene.getObjectByName("backimg1").position.x);

  console.log(offsetX);
  var coords = {
    x: 0,
    y: ZW_Scene.getObjectByName("backimg1").position.y
  };
  new TWEEN.Tween(coords)
    .to({
      x: offsetX,
      y: -0.02
    }, 1000 * 1)
    .repeat(0)
    .easing(TWEEN.Easing.Quadratic.Out)
    .onUpdate(function () {
      ZW_Scene.getObjectByName("backimg1").position.x = pos1 + coords.x;
      ZW_Scene.getObjectByName("backimg2").position.x = pos2 + coords.x;
      ZW_Scene.getObjectByName("backimg3").position.x = pos3 + coords.x;

      ZW_Scene.getObjectByName("backimg1").position.y = coords.y;
      ZW_Scene.getObjectByName("backimg2").position.y = coords.y;
      ZW_Scene.getObjectByName("backimg3").position.y = coords.y;

      //UpdateTipState();
    }).onComplete(function () {
      if (index == 1) {
        ZW_Scene.getObjectByName("backimg2").position.x =
          ZW_Scene.getObjectByName("backimg1").position.x +
          0.1 *
          (canvas.width / canvas.height / 0.5633802816901409) *
          +((0.5 * 2671) / 750 + (0.5 * 2100) / 750.0);
        ZW_Scene.getObjectByName("backimg3").position.x =
          ZW_Scene.getObjectByName("backimg1").position.x -
          (0.1 *
            (canvas.width / canvas.height / 0.5633802816901409) *
            1.0 *
            2671) /
          750;
      } else if (index == 2) {
        ZW_Scene.getObjectByName("backimg2").position.x =
          ZW_Scene.getObjectByName("backimg1").position.x +
          0.1 *
          (canvas.width / canvas.height / 0.5633802816901409) *
          +((0.5 * 2671) / 750 + (0.5 * 2100) / 750.0);
        ZW_Scene.getObjectByName("backimg3").position.x =
          ZW_Scene.getObjectByName("backimg1").position.x -
          (0.1 *
            (canvas.width / canvas.height / 0.5633802816901409) *
            1.0 *
            2671) /
          750;
      } else if (index == 3) {
        ZW_Scene.getObjectByName("backimg1").position.x = (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (-(
          (0.5 * 2671) / 750 +
          (0.5 * 2100) / 750.0
        ));
        ZW_Scene.getObjectByName("backimg3").position.x = (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (+(
          (0.5 * 2671) / 750 +
          (0.5 * 2100) / 750.0
        ));
      } else if (index == 4) {
        ZW_Scene.getObjectByName("backimg1").position.x =
          ZW_Scene.getObjectByName("backimg3").position.x +
          (0.1 *
            (canvas.width / canvas.height / 0.5633802816901409) *
            1.0 *
            2671) /
          750;
        ZW_Scene.getObjectByName("backimg2").position.x =
          ZW_Scene.getObjectByName("backimg3").position.x +
          0.1 *
          (canvas.width / canvas.height / 0.5633802816901409) *
          -((0.5 * 2671) / 750 + (0.5 * 2100) / 750.0);
      } else if (index == 5) {
        ZW_Scene.getObjectByName("backimg1").position.x =
          ZW_Scene.getObjectByName("backimg3").position.x +
          (0.1 *
            (canvas.width / canvas.height / 0.5633802816901409) *
            1.0 *
            2671) /
          750;
        ZW_Scene.getObjectByName("backimg2").position.x =
          ZW_Scene.getObjectByName("backimg3").position.x +
          0.1 *
          (canvas.width / canvas.height / 0.5633802816901409) *
          -((0.5 * 2671) / 750 + (0.5 * 2100) / 750.0);
      }
      UpdateTipState();
    })
    .delay(0)
    .start();
  return;
  // ZW_Scene.getObjectByName('backimg1').position.y = -0.02;
  // ZW_Scene.getObjectByName('backimg2').position.y = -0.02;
  // ZW_Scene.getObjectByName('backimg3').position.y = -0.02;

  // if (index == 1) {
  //   ZW_Scene.getObjectByName('backimg1').position.x = 0.67 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
  //   ZW_Scene.getObjectByName('backimg2').position.x = ZW_Scene.getObjectByName('backimg1').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (+(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));
  //   ZW_Scene.getObjectByName('backimg3').position.x = ZW_Scene.getObjectByName('backimg1').position.x - (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * 1.0 * 2671 / 750;
  // } else if (index == 2) {
  //   ZW_Scene.getObjectByName('backimg1').position.x = -1.22 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409);
  //   ZW_Scene.getObjectByName('backimg2').position.x = ZW_Scene.getObjectByName('backimg1').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (+(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));
  //   ZW_Scene.getObjectByName('backimg3').position.x = ZW_Scene.getObjectByName('backimg1').position.x - (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * 1.0 * 2671 / 750;

  // } else if (index == 3) {
  //   ZW_Scene.getObjectByName('backimg1').position.x = -(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0);
  //   ZW_Scene.getObjectByName('backimg2').position.x = 0;
  //   ZW_Scene.getObjectByName('backimg3').position.x = +(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0);
  // } else if (index == 4) {
  //   ZW_Scene.getObjectByName('backimg3').position.x = 1.23 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)
  //   ZW_Scene.getObjectByName('backimg1').position.x = ZW_Scene.getObjectByName('backimg3').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * 1.0 * 2671 / 750;
  //   ZW_Scene.getObjectByName('backimg2').position.x = ZW_Scene.getObjectByName('backimg3').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (-(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));

  // } else if (index == 5) {
  //   ZW_Scene.getObjectByName('backimg3').position.x = -0.62 * 0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)
  //   ZW_Scene.getObjectByName('backimg1').position.x = ZW_Scene.getObjectByName('backimg3').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * 1.0 * 2671 / 750;
  //   ZW_Scene.getObjectByName('backimg2').position.x = ZW_Scene.getObjectByName('backimg3').position.x + (0.1 * ((canvas.width / canvas.height) / 0.5633802816901409)) * (-(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));
  // }
}

import bottomEnterTestData from "../testData/testBottomEnterData";
import stepTestData from "../../pages/testData/stepData";
var mfApi = require('../../api/api.js');

Page({
  data: {
    canvasId: null,

    isArrow: false,
    baseUrl: app.globalData.baseUrl,
    baseUrl1: LAMER_GLOBAL_URL,

    isAddUpAni: false,
    isShowTips: false,

    // 首次加载
    bFirstLoading: true,
    // 进入其他room视频
    videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/1-ROOM1.mp4',
    posterUrl: '',
    // 是否开始播放进入room视频
    bShowVideo: false,
    // 是否可以操作场景
    isPlay: true,
    picIndex: 1,
    picCurrentIndex: 0,
    currentIndex: 1,

    // 外部传入的跳转信息
    initTurnToPage: null,

    // loading
    isShowLoading: true,

    // 底部入口数据
    bottomEnterData: bottomEnterTestData,

    // 弹窗
    isShotTip: false,
    tipBtnImage: '',
    tipContentImage: '',
    tipIsSmall: true,

    // 印迹数据
    stampData: stepTestData,

    // 规则
    isRuleCont: false
  },

  onLoad(e) {
    console.log("===onLoad===", e);
    this.setData({
      initTurnToPage: e
    });

    if(this.data.initTurnToPage && this.data.initTurnToPage.inChannel) {
      app.globalData.inChannel = this.data.initTurnToPage.inChannel;
    }

    // 二维码扫码进入 处理scene数据
    if (e && e.scene) {
      const scene = decodeURIComponent(e.scene)
      if (scene && scene.length > 0) {
        let tempToData = {};
        let tempGet = scene.split("//");
        if (tempGet[0] == "storyId") {
          tempToData.toPage = "showStory";
          tempToData.storyId = tempGet[1];

          this.setData({
            initTurnToPage: tempToData
          });
        }
      }
    }


    if (ZW_bFirst == false) {
      this.setData({
        isShowTips: true,
        isArrow: true,
        isAddUpAni: true,
      })

    }


    wx.getSystemInfo({
      success: function (res) { // 获取手机信息
        ZW_CurrentModel = res.model;
        ZW_PixelRatio = res.pixelRatio;
        // wx.showToast({
        //   title: res.model,
        //   icon: 'success',
        //   duration: 50000
        //   })
      }
    })

    // wx.showToast({
    //     title: '开始加载',
    //     icon: 'success',
    //     duration: 2000
    //   })

      LoadNum = 28;   //28张图
    that = this;
    wx.createSelectorQuery()
      .select('#c')
      .node()
      .exec((res) => {
        let canvasId = res[0].node._canvasId
        canvas = THREE.global.registerCanvas(canvasId, res[0].node)

        // wx.showToast({
        //     title: '开始加载1',
        //     icon: 'success',
        //     duration: 2000
        //   })

        this.setData({
          canvasId
        })

        ZW_raycaster = new THREE.Raycaster();
        ZW_normalCamera = new THREE.PerspectiveCamera(55, canvas.width / canvas.height, 0.001, 1000);
        //ZW_normalCamera.position.z = 500;

        console.log(canvas.width / canvas.height);
        ZW_Scene = new THREE.Scene();
        ZW_Scene.background = new THREE.Color(0xAAAAAA);
        var renderer = new THREE.WebGLRenderer({
          precision: 'highp',
          antialias: true
        });

        // console.log(ZW_PixelRatio);
        renderer.setPixelRatio(ZW_PixelRatio);

        // renderer.gammaFactor = 3.4;
        // renderer.outputEncoding = THREE.GammaEncoding;

        // const controls = new OrbitControls(camera, renderer.domElement);
        // controls.maxPolarAngle = Math.PI * 0.76; //顶部拖动角度限制
        // controls.minPolarAngle = Math.PI * 0.22; //底部拖动角度限制
        // controls.enableDamping = true;
        // controls.dampingFactor = 0.25;
        // controls.enableZoom = false;

        //mesh.position.x = 0;
        ZW_normalCamera.position.set(0, 0, 2.1);
        ZW_normalCamera.lookAt(new THREE.Vector3(0, 0, 0));
        //controls.update(); 
        //const geometry = new THREE.BoxBufferGeometry(200, 200, 200);

        //AddEnv();
        var date = new Date();
        var hour = new Date().getHours();
        console.log(hour);
        //var type = 2;
        if (hour > 17 || hour < 6) {
          Back_Img_Type = 3;
        } else if (hour > 5 && hour < 12) {
          Back_Img_Type = 1;
        } else {
          Back_Img_Type = 2;
        }
        this.setData({
            picIndex:Back_Img_Type
        });
        
        //Back_Img_Type = 3;
        var url1, url2, url3;
        if (Back_Img_Type == 1) {
          url1 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/1-p1.jpg";
          url2 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/1-p2.jpg";
          url3 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/1-p3.jpg";
        } else if (Back_Img_Type == 2) {
          url1 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/2-p1.jpg";
          url2 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/2-p2.jpg";
          url3 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/2-p3.jpg";
        } else if (Back_Img_Type == 3) {
          url1 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/3-p1.jpg";
          url2 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/3-p2.jpg";
          url3 =
            "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/0427/3-p3.jpg";
        }

        
        AddImage('backimg1', url1, 2671 / 750, 4000 / 750, -(0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));

        AddImage('backimg2', url2, 2100 / 750, 4000 / 750, 0);

        AddImage('backimg3', url3, 2671 / 750, 4000 / 750, (0.5 * 2671 / 750 + 0.5 * 2100 / 750.0));

        // SetRoomState(1, true);
        // SetRoomState(2, true);
        // SetRoomState(3, true);
        // SetRoomState(4, true);
        // SetRoomState(5, false);

        //SetRoom(1);
        //AddImage('backimg','https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/p2-t.jpg',600,900);

        //AddTip('tip1','https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamer-skin/img/tip1.png',152,39,0.006,0.004);
        // AddTip('tip2','https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamer-skin/img/tip2.png',152,39,-0.007,0.0025);
        // AddTip('tip3','https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamer-skin/img/tip3.png',152,39,0.002,-0.004);  

        // AddTip('tip1','https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamer-skin/img/tip1.png',168,382,'right');
        // AddTip('tip2','https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamer-skin/img/tip2.png',125,397,'left');
        // AddTip('tip3','https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamer-skin/img/tip3.png',154,401,'bottom');

        // console.log(GetImagePos('backimg',300,450,1.88));
        // console.log(GetImagePos('backimg',168,382,1.88));
        // console.log(GetImagePos('backimg',152,393,1.88*1.04));


        // for(var i=1; i<136; i++)
        // {
        //   AddCircle('circle'+i,'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/lamer-skin/img/circle/circle%20('+i+').png',600,600); 
        // }

        function oncanvasResize() {
          ZW_normalCamera.aspect = canvas.width / canvas.height;
          ZW_normalCamera.updateProjectionMatrix();
          renderer.setSize(canvas.width, canvas.height);
        }

        function render() {
          canvas.requestAnimationFrame(render);
          // mesh.rotation.x += 0.005;
          // mesh.rotation.y += 0.01;
          //controls.update();
          ControlUpdate();
          TWEEN.update();
          renderer.render(ZW_Scene, ZW_normalCamera);
        }

        render()

      })

    this.videoContext = wx.createVideoContext('myVideo');
    this.bottomView = this.selectComponent("#bottom-enter"); //组件的id

  },

  touchStart(event) {
    //console.log(event);
    

    _clickStart.copy(new THREE.Vector2(event.touches[0].x, event.touches[0].y));

    
    switch (event.touches.length) {
      case 1:
        _state = STATE.TOUCH_ROTATE;
        _moveCurr.copy(getMouseOnCircle(event.touches[0].x, event.touches[0].y));
        _movePrev.copy(_moveCurr);

        break;
      case 2:
        return;
        _state = STATE.TOUCH_PAN;
        var x = (event.touches[0].x + event.touches[1].x) / 2;
        var y = (event.touches[0].y + event.touches[1].y) / 2;
        _panStart.copy(getMouseOnScreen(x, y));
        _panEnd.copy(_panStart);

        var dx = event.touches[0].x - event.touches[1].x;
        var dy = event.touches[0].y - event.touches[1].y;
        if (_touchZoomDistanceStart < 1.001 && _touchZoomDistanceStart > 0.999 && _touchZoomDistanceEnd < 1.001 && _touchZoomDistanceEnd > 0.999) {
          _touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt(dx * dx + dy * dy);
        } else {
          _touchZoomDistanceEnd = parseInt(Math.sqrt(dx * dx + dy * dy));
        }

        break;
      case 3:
        break;
      default:
        break;
    }
    //THREE.global.touchEventHandlerFactory('canvas', 'touchstart')(e)
  },
  touchMove(event) {
    switch (event.touches.length) {
      case 1:
        if (_state === STATE.TOUCH_ROTATE) {

          //if(ZW_SceneParent.getObjectByName('ZW_33')) ZW_SceneParent.getObjectByName('ZW_33').getObjectByName('RAILS').visible = false;

          // that.setData({
          //   isShowTips: false
          // });
          //HideOrShowTab(false);
          _movePrev.copy(_moveCurr);
          //console.log(_moveCurr);

          _moveCurr.copy(getMouseOnCircle(event.touches[0].x, event.touches[0].y));


          // that.setData({
          //   infoText: event.touches[0].x + ',' + event.touches[0].y
          // });
        }
        break;
      case 2:
        return;
        showTime = (new Date()).getTime();
        //HideOrShowTab(false);

        //_state = STATE.TOUCH_ZOOM_PAN;
        // if(ZW_SceneParent.getObjectByName('ZW_33')) ZW_SceneParent.getObjectByName('ZW_33').getObjectByName('RAILS').visible = false;

        if (_state === STATE.TOUCH_PAN) {
          var dx = event.touches[0].x - event.touches[1].x;
          var dy = event.touches[0].y - event.touches[1].y;
          if (_touchZoomDistanceStart < 1.001 && _touchZoomDistanceStart > 0.999 && _touchZoomDistanceEnd < 1.001 && _touchZoomDistanceEnd > 0.999) {
            _touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt(dx * dx + dy * dy);
          } else {
            _touchZoomDistanceEnd = parseInt(Math.sqrt(dx * dx + dy * dy));
          }


          var x = (event.touches[0].x + event.touches[1].x) / 2;
          var y = (event.touches[0].y + event.touches[1].y) / 2;
          //_panStart.copy(getMouseOnScreen(x, y));
          _zoomStart.x = x;
          _zoomStart.y = y;
        }

        if (_state === STATE.TOUCH_PAN) {
          var x = (event.touches[0].x + event.touches[1].x) / 2;
          var y = (event.touches[0].y + event.touches[1].y) / 2;
          _panEnd.copy(getMouseOnScreen(x, y));
        }
        break;
      default:
        break;
    }


    // THREE.global.touchEventHandlerFactory('canvas', 'touchmove')(e)
  },
  touchEnd(event) {
    if(that.data.isShowLoading || that.data.isShotTip || that.data.isRuleCont)
      return;
    _clickEnd.copy(new THREE.Vector2(event.changedTouches[0].x, event.changedTouches[0].y));

    var mouse = new THREE.Vector2();
    mouse.x = ((event.changedTouches[0].x * ZW_PixelRatio) / (canvas.width)) * 2 - 1;
    mouse.y = -((event.changedTouches[0].y * ZW_PixelRatio) / (canvas.height)) * 2 + 1;

		var dx = _clickStart.x - _clickEnd.x;
		var dy = _clickStart.y - _clickEnd.y;
		var distance = Math.sqrt(dx * dx + dy * dy);	//按下与松开手指的距离，太远不响应，近一些认为是点击

		if (distance < 50) {
            var mymodel1 = ZW_Scene.getObjectByName('backimg1').getObjectByName('door1');
            var mymodel2 = ZW_Scene.getObjectByName('backimg1').getObjectByName('door2');
            var mymodel3 = ZW_Scene.getObjectByName('backimg2').getObjectByName('door3');
            var mymodel4 = ZW_Scene.getObjectByName('backimg3').getObjectByName('door4');
            var mymodel5 = ZW_Scene.getObjectByName('backimg3').getObjectByName('door5');

            var e1 = ZW_Scene.getObjectByName('backimg1').getObjectByName('tip13');
            var e2 = ZW_Scene.getObjectByName('backimg1').getObjectByName('tip23');
            var e3 = ZW_Scene.getObjectByName('backimg2').getObjectByName('tip33');
            var e4 = ZW_Scene.getObjectByName('backimg3').getObjectByName('tip43');
            var e5 = ZW_Scene.getObjectByName('backimg3').getObjectByName('tip53');

            var f1 = ZW_Scene.getObjectByName('backimg1').getObjectByName('tip14');
            var f2 = ZW_Scene.getObjectByName('backimg1').getObjectByName('tip24');
            var f3 = ZW_Scene.getObjectByName('backimg2').getObjectByName('tip34');
            var f4 = ZW_Scene.getObjectByName('backimg3').getObjectByName('tip44');
            var f5 = ZW_Scene.getObjectByName('backimg3').getObjectByName('tip54');


            ZW_raycaster.setFromCamera(mouse, ZW_normalCamera);

            var interArray = [];
            if (mymodel1) interArray.push(mymodel1);
            if (mymodel2) interArray.push(mymodel2);
            if (mymodel3) interArray.push(mymodel3);
            if (mymodel4) interArray.push(mymodel4);
            if (mymodel5) interArray.push(mymodel5);

            if (e1) interArray.push(e1);
            if (e2) interArray.push(e2);
            if (e3) interArray.push(e3);
            if (e4) interArray.push(e4);
            if (e5) interArray.push(e5);

            if (f1) interArray.push(f1);
            if (f2) interArray.push(f2);
            if (f3) interArray.push(f3);
            if (f4) interArray.push(f4);
            if (f5) interArray.push(f5);

            if (interArray.length > 0) {
                var intersects = ZW_raycaster.intersectObjects(interArray, true);


                if (intersects.length > 0) {
                    console.log(intersects[0].object.name);
                    if (intersects[0].object.name == 'tip13' || intersects[0].object.name == 'door1') {
                        if (ZW_RoomStateArray[0]) {
                            that.enterRoom1();
                            console.log('进入房间1');
                            app.saveTrack(`大厅-进入房间1`);
                        } else {
                            console.log('房间1被锁定');
                        }
                    } else if (intersects[0].object.name == 'tip23' || intersects[0].object.name == 'door2') {
                        if (ZW_RoomStateArray[1]) {
                            that.enterRoom2();
                            console.log('进入房间2');
                            app.saveTrack(`大厅-进入房间2`);
                        } else {
                            console.log('房间2被锁定');
                        }
                    } else if (intersects[0].object.name == 'tip33' || intersects[0].object.name == 'door3') {
                        if (ZW_RoomStateArray[2]) {
                            that.enterRoom3();
                            console.log('进入房间3');
                            app.saveTrack(`大厅-进入房间3`);
                        } else {
                            console.log('房间3被锁定');
                        }
                    } else if (intersects[0].object.name == 'tip43' || intersects[0].object.name == 'door4') {
                        if (ZW_RoomStateArray[3]) {
                            that.enterRoom4();
                            console.log('进入房间4');
                            app.saveTrack(`大厅-进入房间4`);
                        } else {
                            console.log('房间4被锁定');
                        }
                    } else if (intersects[0].object.name == 'tip53' || intersects[0].object.name == 'door5') {
                        if (ZW_RoomStateArray[4]) {
                            that.enterRoom5();
                            console.log('进入房间5');
                            app.saveTrack(`大厅-进入房间5`);
                        } else {
                            console.log('房间5被锁定');
                            that.setData({
                                isShotTip: true,
                                tipIsSmall: true,
                                tipBtnImage: that.data.baseUrl + '/index/btn-explorer.png',
                                tipContentImage: that.data.baseUrl + '/index/tip-lock-r5.png',
                            })
                            SetRoom(1);
                        }
                    } else if (intersects[0].object.name == 'tip14') {
                        console.log('房间1治愈指南');
                        that.setData({
                            isRuleCont: true
                        })
                        app.saveTrack(`大厅-房间_1_治愈指南`);
                    } else if (intersects[0].object.name == 'tip24') {
                        console.log('房间2治愈指南');
                        that.setData({
                            isRuleCont: true
                        })
                        app.saveTrack(`大厅-房间_2_治愈指南`);
                    } else if (intersects[0].object.name == 'tip34') {
                        console.log('房间3治愈指南');
                        that.setData({
                            isRuleCont: true
                        })
                        app.saveTrack(`大厅-房间_3_治愈指南`);
                    } else if (intersects[0].object.name == 'tip44') {
                        console.log('房间4治愈指南');
                        that.setData({
                            isRuleCont: true
                        })
                        app.saveTrack(`大厅-房间_4_治愈指南`);
                    } else if (intersects[0].object.name == 'tip54') {
                        console.log('房间5治愈指南');
                        that.setData({
                            isRuleCont: true
                        })
                        app.saveTrack(`大厅-房间_5_治愈指南`);
                    }
                }
            }
        }
    switch (event.touches.length) {
      case 0:
        _state = STATE.NONE;
        _touchZoomDistanceEnd = _touchZoomDistanceStart = 1;
        _panStart.copy(_panEnd);

        RotateCamera();
        // if(ZW_SceneParent.getObjectByName('ZW_33')) ZW_SceneParent.getObjectByName('ZW_33').getObjectByName('RAILS').visible = true;
        break;
      default:
        _state = STATE.NONE;
        _moveCurr.copy(getMouseOnCircle(event.touches[0].x, event.touches[0].y));
        _movePrev.copy(_moveCurr);
        _touchZoomDistanceEnd = _touchZoomDistanceStart = 1;
        _panStart.copy(_panEnd);

        break;
    }
    // THREE.global.touchEventHandlerFactory('canvas', 'touchend')(e)
  },

onShareTimeline:function(){
 
},
  async onShow() {
    console.log("===onShow===");
    if (!ZW_bFirst) {
      
      // if(!this.data.isShowLoading)
        await this.checkUser();
      // this.checkExternalTurnData();
      // 从其他房间点击底部入口  返回index后 场景跳转到点击的入口
      if (app.globalData.indexTurnDoor != -1) {
        SetRoom(app.globalData.indexTurnDoor);
        app.globalData.indexTurnDoor = -1;
        app.globalData.isFromShareDoor = false;
      }
    } else {
      ZW_bFirst = false;
    }
  },

  sleep(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
      now = new Date();
      if (now.getTime() > exitTime)
        return;
    }
  },
  async onLoadingFinish() {
    // 不管怎么样，先触发埋点
    app.saveTrack(' ', true);
    app.saveTrack('Loading-探索大厅-Click ');
    //   this.sleep(3000);
    if(LoadNum > 0) return;
    console.log("===onResLoaded===");
    this.setData({
      isPlay: true,
      bFirstLoading: false,
      isShowLoading: false
    })
    await this.checkUser();

    this.bottomView.setDefaultIsExpand(app.globalData.isBottomEnterExpand);
    this.checkExternalTurnData();
  },

  checkExternalTurnData() {
    if (this.data.initTurnToPage) {
      // 渠道判断
      // inChannel=wx_official_account 公众号
      if(this.data.initTurnToPage.inChannel) {
        app.saveTrack(`进入来自渠道-${this.data.initTurnToPage.inChannel}` );
        app.globalData.inChannel = this.data.initTurnToPage.inChannel;
      }

      // 进入的页面及参数
      if (this.data.initTurnToPage.toPage == "videoSwiper") {
        // 分享视频进入
        app.saveTrack(`enter-from-video-share`);
        app.globalData.gCurrentRoomIndex = Number(this.data.initTurnToPage.selectRoom);
        
        console.log("checkExternalTurnData --- isHori = " + this.data.initTurnToPage.isHori)
        if(this.data.initTurnToPage.isHori == 'true') {
          wx.navigateTo({
            url: '/pages/videoSwiperHoriPage/videoSwiperHoriPage?selectId=' + this.data.initTurnToPage.selectId,
          })
        } else {
          wx.navigateTo({
            url: '/pages/videoSwiperPage/videoSwiperPage?selectId=' + this.data.initTurnToPage.selectId,
          })
        }
      } else if (this.data.initTurnToPage.toPage == "showStory") {
        // 分享证书进入
        console.log("======-=-=-=-=   show story -=-=-============")
        app.saveTrack(`enter-from-story-share`);
        app.globalData.gCurrentRoomIndex = 5;
        wx.navigateTo({
          url: '/pages/storyShowPage/storyShowPage?storyId=' + this.data.initTurnToPage.storyId,
        })
      } else if(this.data.initTurnToPage.toPage == "giveLuckDraw") {
        // 分享奖品进入
        app.saveTrack(`enter-from-luckdraw-share`);
        wx.navigateTo({
          url: '/pages/luckDraw/luckDrawIndex?inUserAwardId=' + this.data.initTurnToPage.userAwardId,
        })
      } else if(this.data.initTurnToPage.toPage == "room") {
        // 外部房间进入
        app.saveTrack(`enter-from-enterRoom${this.data.initTurnToPage.toRoomNo}`);
        if(this.data.initTurnToPage.toRoomNo >= 1 && this.data.initTurnToPage.toRoomNo <= 4) {
          app.globalData.gCurrentRoomIndex = this.data.initTurnToPage.toRoomNo;
          wx.navigateTo({
            url: '/pages/normalRoom/normalRoom'
          })
        } else if(this.data.initTurnToPage.toRoomNo == 5) {
          // let r5info = this.data.bottomEnterData.find(e => {
          //   return e.enterIndex == 5
          // })
          // if(r5info.unlockFlag != '1') {
          //   console.log('房间5被锁定');
          //   that.setData({
          //       isShotTip: true,
          //       tipIsSmall: true,
          //       tipBtnImage: that.data.baseUrl + '/index/btn-explorer.png',
          //       tipContentImage: that.data.baseUrl + '/index/tip-lock-r5.png',
          //   })
          //   SetRoom(1);
          //   return;
          // }
          
          app.globalData.gCurrentRoomIndex = this.data.initTurnToPage.toRoomNo;
          wx.navigateTo({
            url:  "/pages/room5/roomIndex/roomIndex"
          })
        }
      }

      // wx.navigateTo({
      //   url: '/pages/luckDraw/luckDrawIndex?inUserAwardId=' + "1516278512154923009",
      // })

      this.setData({
        initTurnToPage: null
      })
    }
  },

  async checkUser() {
    console.log("===checkUser===");

    let res = await mfApi.http(
      mfApi.getRoomList(app.globalData.openId), "GET", {});
    if (res.code != 200)
      return;

    let tempStampData = this.data.stampData;
    tempStampData.forEach(element => {
      // element.index
      let roomInfo = res.result.roomList.find(e => {
        return e.roomNo == element.index;
      });
      if (roomInfo) {
        SetRoomState(roomInfo.roomNo, roomInfo.unlockFlag == '1');
        element.markFlag = roomInfo.markFlag;
      }
    })

    let indexData = tempStampData.find(e => {
      return e.index == 6
    })

    indexData.markFlag = res.result.shareVideoMarkFlag;

    this.setData({
      stampData: tempStampData
    })

    let tempEnterData = this.data.bottomEnterData;
    tempEnterData.forEach(element => {
      // element.index
      let roomInfo = res.result.roomList.find(e => {
        return e.roomNo == element.enterIndex;
      });
      if (roomInfo)
        element.unlockFlag = roomInfo.unlockFlag;
    })

    this.setData({
      bottomEnterData: tempEnterData
    })

    // app.globalData.indexTurnDoor = 5;
    // app.globalData.isFromShareDoor = true;

    let infRes = await mfApi.http(
      mfApi.getUserInfo(app.globalData.openId), "POST", {
        "avatar": app.globalData.userIcon,
        "nickName": app.globalData.userName,
      });
    if (infRes.code == 200) {
      let r5info = res.result.roomList.find(e => {
        return e.roomNo == 5;
      });

      // r5info.unlockFlag = "0"

      // 查看分享证书页回大厅，如果点了r5，r5被锁，弹窗
      if(app.globalData.isFromShareDoor 
        && app.globalData.indexTurnDoor == 5 && r5info.unlockFlag == '0') {
        this.setData({
          isShotTip: true,
          tipIsSmall: true,
          tipBtnImage: this.data.baseUrl + '/index/btn-explorer.png',
          tipContentImage: this.data.baseUrl + '/index/tip-lock-r5.png',
        })
        app.globalData.indexTurnDoor = 1;

        app.globalData.needFirstFrame = false;
        return;
      }
      
      // 
      if (infRes.result.todayFirstFlag == '1' || app.globalData.needFirstFrame) {
        this.setData({
          isShotTip: true,
          tipIsSmall: false,
          tipBtnImage: this.data.baseUrl + '/index/btn-explorer.png?t=1',
          tipContentImage: this.data.baseUrl + '/index/tip-start.png?t=1',
        })
        app.globalData.isBottomEnterExpand = true;
        app.globalData.needFirstFrame = false;
      }
    }

  },



  // this.setData()

  /**
   * 进入房间视频播放结束
   */
  onEnded() {
    let subPages = [
      "/pages/normalRoom/normalRoom",
      "/pages/normalRoom/normalRoom",
      "/pages/normalRoom/normalRoom",
      "/pages/normalRoom/normalRoom",
      "/pages/normalRoom/normalRoom",
      "/pages/room5/roomIndex/roomIndex"
    ];
    app.globalData.gCurrentRoomIndex = this.data.currentIndex;

    // app.saveTrack(`进入房间${app.globalData.gCurrentRoomIndex}`);
    wx.navigateTo({
      url: subPages[this.data.currentIndex]
    });

    setTimeout(() => {
      this.setData({
        bShowVideo: false,
        isArrow: true
      })
    }, 500);
  },

  /**
   * 设置视频播放状态
   * @param {*} e 
   */
  onVideoUpdate(e) {
    if (e.detail.currentTime > 0.1) {
      this.setData({
        isPlay: true,
        picCurrentIndex: 0
      })
    }
  },

  enterRoom1: function () {
    this.setData({
        picCurrentIndex: 1
      })
    this.onVideoStart(1);
    // that.setData({
    //   videoUrl:LAMER_GLOBAL_URL + '/img/20210909/Portal1.mp4',
    //       bShowVideo:true
    //     })
    // wx.showToast({
    //   title: 'enterRoom1',
    //   icon: 'success',
    //   duration: 2000
    // })
  },
  enterRoom2: function () {
    this.setData({
        picCurrentIndex: 2
      })

    this.onVideoStart(2);

  },
  enterRoom3: function () {

    this.setData({
        picCurrentIndex: 3
      })
    this.onVideoStart(3);
  },
  enterRoom4: function () {

    this.setData({
        picCurrentIndex: 4
      })
    this.onVideoStart(4);
  },
  enterRoom5: function () {
    this.setData({
        picCurrentIndex: 5
      })

    this.onVideoStart(5);
  },
  enterRoom6: function () {
    this.onVideoStart(6);
  },

  onVideoStart(value) {
    if (Back_Img_Type == 1) {
      if (value == 1) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 1,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/1-ROOM1.mp4',
          posterUrl: ''
        })
      } else if (value == 2) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 2,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/1-ROOM2.mp4',
          posterUrl: ''
        })
      } else if (value == 3) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 3,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/1-ROOM3.mp4',
          posterUrl: ''
        })
      } else if (value == 4) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 4,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/1-ROOM4.mp4',
          posterUrl: ''
        })
      } else if (value == 5) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 5,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/1-ROOM5.mp4',
          posterUrl: ''
        })
      }
    }else if (Back_Img_Type == 2) {
      if (value == 1) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 1,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/2-ROOM1.mp4',
          posterUrl: ''
        })
      } else if (value == 2) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 2,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/2-ROOM2.mp4',
          posterUrl: ''
        })
      } else if (value == 3) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 3,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/2-ROOM3.mp4',
          posterUrl: ''
        })
      } else if (value == 4) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 4,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/2-ROOM4.mp4',
          posterUrl: ''
        })
      } else if (value == 5) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 5,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/2-ROOM5.mp4',
          posterUrl: ''
        })
      }
    }else if (Back_Img_Type == 3) {
      if (value == 1) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 1,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/3-ROOM1.mp4',
          posterUrl: ''
        })
      } else if (value == 2) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 2,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/3-ROOM2.mp4',
          posterUrl: ''
        })
      } else if (value == 3) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 3,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/3-ROOM3.mp4',
          posterUrl: ''
        })
      } else if (value == 4) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 4,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/3-ROOM4.mp4',
          posterUrl: ''
        })
      } else if (value == 5) {
        this.videoContext.play();
        this.setData({
          bShowVideo: true,
          isPlay: false,
          currentIndex: 5,
          videoUrl: 'https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/cream/20220418-m/3-ROOM5.mp4',
          posterUrl: ''
        })
      }
    }
    
    this.setData({
      isArrow: false
    })
  },

  /**
   * 点击底部入口list
   * @param {*} e 
   */
  onRoomSelect(e) {
    console.log("===selectRoom===", e);

    let {
      idx,
      status
    } = e.currentTarget.dataset;
    if (status !== 0) {
      this.onVideoStart(idx)
      //app.saveTrack('选择房间' + idx, '')
    }
  },

  exchangeModel(index) {
    this.setData({
      isShowTips: false
    });
    // $global.canvas.gSwitchScene(index);
    //my.alert({content:'sdf'});
  },

  onTouchMove(e) {
    console.log("===onTouchMove==")
    this.closeTip()
  },

  onTipBtnClick() {
    this.setData({
      isShotTip: false,
    })
    app.saveTrack(`大厅-立即开始`);
  },

  onTipBtnCloseClick() {
    this.setData({
      isShotTip: false,
    })
  },

  onLuckClick() {
    app.saveTrack(`大厅-治愈礼盒`);
    wx.navigateTo({
      url: '/pages/luckDraw/luckDrawIndex',
    })
  },

  /**
   * 底部入口点击
   */
  onBottomEnterClick(e) {
    console.log(e.detail)
    SetRoom(e.detail)
  },

  onRoleClick() {
    this.setData({
      isRuleCont: false
    })
  },

  onShareAppMessage(object) {
    return {
      title: 'LA MER邀你一同参展，探寻属于你的自愈空间',
      path: `/pages/index/index?inChannel=commonShare`,
      imageUrl: "https://morefun-active-1.oss-cn-shanghai.aliyuncs.com/2022_lamer_cream_show/share/wx-share.jpg",
    }
  }
})